﻿// -----------------------------------------------------------------------
// <copyright file="ColorType.cs">
// Copyright (c) 2013 Andrey Veselov. All rights reserved.
// License:  Microsoft Public License (MS-PL)
// Contacts: http://andrey.moveax.com  andrey@moveax.com
// </copyright>
// -----------------------------------------------------------------------

namespace PortableImagingLibrary.Png
{
    using System;

    public enum ColorType : byte
    {
        Greyscale = 0,
        Truecolor = 2,
        IndexedColor = 3,
        GreyscaleWithAlpha = 4,
        TruecolorWithAlpha = 6
    }

    internal static class ColorTypeExtensions
    {
        public static int ElementsPerSample(this ColorType colorType)
        {
            switch (colorType) {
                case ColorType.Greyscale:
                    return 1;

                case ColorType.Truecolor:
                    return 3;

                case ColorType.IndexedColor:
                    return 1;

                case ColorType.GreyscaleWithAlpha:
                    return 2;

                case ColorType.TruecolorWithAlpha:
                    return 4;

                default:
                    throw new ArgumentOutOfRangeException();
            }
        }

        public static bool ContainsAlpha(this ColorType colorType)
        {
            return colorType == ColorType.GreyscaleWithAlpha || colorType == ColorType.TruecolorWithAlpha;
        }
    }
}